package com.ecommerce.product.entity;

import com.baomidou.mybatisplus.annotation.*;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

import javax.persistence.*;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import java.time.LocalDateTime;
import java.util.List;

/**
 * 商品评价实体类
 * 
 * @author ecommerce-team
 * @version 1.0.0
 */
@Entity
@Table(name = "product_review")
@TableName("product_review")
public class ProductReview {
    
    /**
     * 评价ID
     */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @TableId(value = "id", type = IdType.AUTO)
    private Long id;
    
    /**
     * 商品ID
     */
    @NotNull(message = "商品ID不能为空")
    @Column(name = "product_id", nullable = false)
    private Long productId;
    
    /**
     * 用户ID
     */
    @NotNull(message = "用户ID不能为空")
    @Column(name = "user_id", nullable = false)
    private Long userId;
    
    /**
     * 订单ID
     */
    @Column(name = "order_id")
    private Long orderId;
    
    /**
     * 用户名（脱敏处理）
     */
    @Column(name = "username", length = 50)
    private String username;
    
    /**
     * 用户头像
     */
    @Column(name = "avatar", length = 500)
    private String avatar;
    
    /**
     * 评分（1-5星）
     */
    @NotNull(message = "评分不能为空")
    @Min(value = 1, message = "评分不能小于1")
    @Max(value = 5, message = "评分不能大于5")
    @Column(name = "rating", nullable = false)
    private Integer rating;
    
    /**
     * 评价内容
     */
    @Column(name = "content", columnDefinition = "text")
    private String content;
    
    /**
     * 评价图片（JSON格式）
     */
    @Column(name = "images", columnDefinition = "text")
    private String images;
    
    /**
     * 是否匿名：0-否，1-是
     */
    @Column(name = "is_anonymous", columnDefinition = "tinyint default 0")
    private Integer isAnonymous;
    
    /**
     * 是否置顶：0-否，1-是
     */
    @Column(name = "is_top", columnDefinition = "tinyint default 0")
    private Integer isTop;
    
    /**
     * 点赞数
     */
    @Column(name = "like_count", columnDefinition = "int default 0")
    private Integer likeCount;
    
    /**
     * 回复数
     */
    @Column(name = "reply_count", columnDefinition = "int default 0")
    private Integer replyCount;
    
    /**
     * 审核状态：0-待审核，1-审核通过，2-审核拒绝
     */
    @Column(name = "audit_status", columnDefinition = "tinyint default 0")
    private Integer auditStatus;
    
    /**
     * 创建时间
     */
    @TableField(fill = FieldFill.INSERT)
    @Column(name = "create_time", nullable = false, updatable = false)
    private LocalDateTime createTime;
    
    /**
     * 更新时间
     */
    @TableField(fill = FieldFill.INSERT_UPDATE)
    @Column(name = "update_time", nullable = false)
    private LocalDateTime updateTime;
    
    /**
     * 逻辑删除：0-未删除，1-已删除
     */
    @TableLogic
    @Column(name = "deleted", columnDefinition = "tinyint default 0")
    private Integer deleted;
    
    // 以下字段不存储到数据库，仅用于返回给前端
    
    /**
     * 评价图片列表（不存储到数据库）
     */
    @Transient
    @TableField(exist = false)
    private List<String> imageList;
    
    /**
     * 评价时间格式化字符串（不存储到数据库）
     */
    @Transient
    @TableField(exist = false)
    private String time;
    
    // Getter and Setter methods
    public Long getId() { return id; }
    public void setId(Long id) { this.id = id; }
    
    public Long getProductId() { return productId; }
    public void setProductId(Long productId) { this.productId = productId; }
    
    public Long getUserId() { return userId; }
    public void setUserId(Long userId) { this.userId = userId; }
    
    public Long getOrderId() { return orderId; }
    public void setOrderId(Long orderId) { this.orderId = orderId; }
    
    public String getUsername() { return username; }
    public void setUsername(String username) { this.username = username; }
    
    public String getAvatar() { return avatar; }
    public void setAvatar(String avatar) { this.avatar = avatar; }
    
    public Integer getRating() { return rating; }
    public void setRating(Integer rating) { this.rating = rating; }
    
    public String getContent() { return content; }
    public void setContent(String content) { this.content = content; }
    
    public String getImages() { return images; }
    public void setImages(String images) { this.images = images; }
    
    public Integer getIsAnonymous() { return isAnonymous; }
    public void setIsAnonymous(Integer isAnonymous) { this.isAnonymous = isAnonymous; }
    
    public Integer getIsTop() { return isTop; }
    public void setIsTop(Integer isTop) { this.isTop = isTop; }
    
    public Integer getLikeCount() { return likeCount; }
    public void setLikeCount(Integer likeCount) { this.likeCount = likeCount; }
    
    public Integer getReplyCount() { return replyCount; }
    public void setReplyCount(Integer replyCount) { this.replyCount = replyCount; }
    
    public Integer getAuditStatus() { return auditStatus; }
    public void setAuditStatus(Integer auditStatus) { this.auditStatus = auditStatus; }
    
    public LocalDateTime getCreateTime() { return createTime; }
    public void setCreateTime(LocalDateTime createTime) { this.createTime = createTime; }
    
    public LocalDateTime getUpdateTime() { return updateTime; }
    public void setUpdateTime(LocalDateTime updateTime) { this.updateTime = updateTime; }
    
    public Integer getDeleted() { return deleted; }
    public void setDeleted(Integer deleted) { this.deleted = deleted; }
    
    public List<String> getImageList() { return imageList; }
    public void setImageList(List<String> imageList) { this.imageList = imageList; }
    
    public String getTime() { return time; }
    public void setTime(String time) { this.time = time; }
}